import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/*
得到role名后调用roles对应的权限 [login','icons',....]
* route.meta.roles: ['login']
* roles.some(role => route.meta.roles.includes(role)) 判断角色中包含此权限
* */

//定义角色
const superAdmin='superadmin'
const ordinary='ordinary'
const editor='editor'


/* Layout */
import Layout from '@/pages/layout/Layout'

/* Router Modules */
import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'
import adminRouter from './modules/admin'

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: [superAdmin,editor]     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [


  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/pages/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/pages/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
      }
    ]
  },
  /* {
     path: '/documentation',
     component: Layout,
     redirect: '/documentation/index',
     children: [
       {
         path: 'index',
         component: () => import('@/views/documentation/index'),
         name: 'Documentation',
         meta: { title: 'documentation', icon: 'documentation', noCache: true }
       }
     ]
   },
   {
     path: '/guide',
     component: Layout,
     redirect: '/guide/index',
     children: [
       {
         path: 'index',
         component: () => import('@/views/guide/index'),
         name: 'Guide',
         meta: { title: 'guide', icon: 'guide', noCache: true }
       }
     ]
   }*/
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
export const asyncRouterMap = [
/*  //备件查询
  {
    path: '/queryItem',
    component: Layout,
    redirect: '/queryItem/qi',
    name: 'queryItem',
    meta: { role: [superAdmin],title: 'queryItem', icon: 'component'},
    children: [
      {path: 'qi', name: 'qi', component:() => import('@/pages/QueryItem/qi'), meta: {title: 'qi',noCache: true }},
      {path: 'subtest', name: 'subtest', component:() => import('@/pages/QueryItem/subtest'), meta: {title: 'subtest',noCache: true }},
    ]
  },*/
  //编码管理
/*  {
    path: '/codesManage',
    component: Layout,
    redirect: '/codesManage/qi',
    name: 'codesManage',
    meta: { role: [superAdmin],title: 'codesManage', icon: 'component'},
    children: [
      {path: 'applyCode', name: 'applyCode', component:() => import('@/pages/codesManage/applyCode'), meta: {title: 'applyCode',noCache: true }},
      {path: 'auditCode', name: 'auditCode', component:() => import('@/pages/codesManage/auditCode'), meta: {title: 'auditCode',noCache: true }},
      {path: 'codeCategory', name: 'codeCategory', component:() => import('@/pages/codesManage/codeCategory'), meta: {title: 'codeCategory',noCache: true }},
      {path: 'codeImport', name: 'codeImport', component:() => import('@/pages/codesManage/codeImport'), meta: {title: 'codeImport',noCache: true }},
    ]
  },*/
  //编码管理
  {
    path: '/codeManage',
    component: Layout,
    redirect: '/codeManage/qi',
    name: 'codeManage',
    meta: { role: [superAdmin],title: 'codeManage', icon: 'component'},
    children: [
      {path: 'applyCode', name: 'applyCode', component:() => import('@/pages/codeManage/applyCode'), meta: {title: 'applyCode',noCache: true }},
      {path: 'auditCode', name: 'code_flowable', component:() => import('@/pages/codeManage/auditCode'), meta: {title: 'auditCode',noCache: true }},
      {path: 'codeCategory', name: 'codeCategory', component:() => import('@/pages/codeManage/codeCategory'), meta: {title: 'codeCategory',noCache: true }},
      {path: 'codeImport', name: 'codeImport', component:() => import('@/pages/codeManage/codeImport'), meta: {title: 'codeImport',noCache: true }},
      {path: 'codeFlow', name: 'codeFlow', component:() => import('@/pages/codeManage/codeFlow'), meta: {title: 'codeFlow',noCache: true }},
    ]
  },
  //供应商管理
  {
    path: '/supplierManage',
    component: Layout,
    redirect: '/supplierManage/supplierApply',
    name: 'supplierManage',
    meta: { role: [superAdmin],title: 'supplierManage', icon: 'component'},
    children: [
      {path: 'supplierApply', name: 'supplierApply', component:() => import('@/pages/supplierManage/supplierApply'), meta: {title: 'supplierApply',noCache: true }},
      {path: 'supplierAudit', name: 'supplierAudit', component:() => import('@/pages/supplierManage/supplierAudit'), meta: {title: 'supplierAudit',noCache: true }},
      {path: 'supplierCategory', name: 'supplierCategory', component:() => import('@/pages/supplierManage/supplierCategory'), meta: {title: 'supplierCategory',noCache: true }},
      {path: 'supplierEvaluation', name: 'supplierEvaluation', component:() => import('@/pages/supplierManage/supplierEvaluation'), meta: {title: 'supplierEvaluation',noCache: true }},
    ]
  },

  //计划管理
  {
    path: '/planManage',
    component: Layout,
    redirect: '/planManage/planApply',
    name: 'planManage',
    meta: { role: [superAdmin],title: 'planManage', icon: 'component'},
    children: [
      {path: 'planApply', name: 'planApply', component:() => import('@/pages/planManage/planApply'), meta: {title: 'planApply',noCache: true }},
      {path: 'planAudit', name: 'planAudit', component:() => import('@/pages/planManage/planAudit'), meta: {title: 'planAudit',noCache: true }},
      {path: 'planList', name: 'planList', component:() => import('@/pages/planManage/planList'), meta: {title: 'planList',noCache: true }},
      {path: 'planImplement', name: 'planImplement', component:() => import('@/pages/planManage/planImplement'), meta: {title: 'planImplement',noCache: true }},
      {path: 'planTodo', name: 'planTodo', component:() => import('@/pages/planManage/planTodo'), meta: {title: 'planTodo',noCache: true }},
    ]
  },
  //合同管理
  {
    path: '/contractManage',
    component: Layout,
    redirect: '/contractManage/contractApply',
    name: 'contractManage',
    meta: { role: [superAdmin],title: 'contractManage', icon: 'component'},
    children: [
      {path: 'contractApply', name: 'contractApply', component:() => import('@/pages/contractManage/contractApply'), meta: {title: 'contractApply',noCache: true }},
      {path: 'contractAudit', name: 'contractAudit', component:() => import('@/pages/contractManage/contractAudit'), meta: {title: 'contractAudit',noCache: true }},
      {path: 'contractList', name: 'contractList', component:() => import('@/pages/contractManage/contractList'), meta: {title: 'contractList',noCache: true }},
      {path: 'contractChange', name: 'contractChange', component:() => import('@/pages/contractManage/contractChange'), meta: {title: 'contractChange',noCache: true }},
      {path: 'contractLedger', name: 'contractLedger', component:() => import('@/pages/contractManage/contractLedger'), meta: {title: 'contractLedger',noCache: true }},
    ]
  },
  //入库管理
  {
    path: '/inStockManage',
    component: Layout,
    redirect: '/inStockManage/partsCheck',
    name: 'inStockManage',
    meta: { role: [superAdmin],title: 'inStockManage', icon: 'component'},
    children: [
      {path: 'partsCheck', name: 'partsCheck', component:() => import('@/pages/inStockManage/partsCheck'), meta: {title: 'partsCheck',noCache: true }},
      {path: 'inBuy', name: 'inBuy', component:() => import('@/pages/inStockManage/inBuy'), meta: {title: 'inBuy',noCache: true }},
      {path: 'inAllocation', name: 'inAllocation', component:() => import('@/pages/inStockManage/inAllocation'), meta: {title: 'inAllocation',noCache: true }},
      {path: 'errorSearch', name: 'errorSearch', component:() => import('@/pages/inStockManage/errorSearch'), meta: {title: 'errorSearch',noCache: true }},
    ]
  },
  //出库管理
  {
    path: '/outOfStock',
    component: Layout,
    redirect: '/outOfStock/list',
    name: 'outOfStock',
    meta: { role: [superAdmin],title: 'outOfStock', icon: 'component'},
    children: [
      {path: 'outgoingApply', name: 'outgoingApply', component:() => import('@/pages/outOfStock/outgoingApply'), meta: {title: 'outgoingApply',noCache: true }},
      {path: 'outgoingRecord', name: 'outgoingRecord', component:() => import('@/pages/outOfStock/outgoingRecord'), meta: {title: 'outgoingRecord',noCache: true }},
      {path: 'applyAllocation', name: 'applyAllocation', component:() => import('@/pages/outOfStock/applyAllocation'), meta: {title: 'applyAllocation',noCache: true }},
      {path: 'recordAllocation', name: 'recordAllocation', component:() => import('@/pages/outOfStock/recordAllocation'), meta: {title: 'recordAllocation',noCache: true }},
      {path: 'drawsBack', name: 'drawsBack', component:() => import('@/pages/outOfStock/drawsBack'), meta: {title: 'drawsBack',noCache: true }},
    ]
  },
  //库存管理
  {
    path: '/stockManage',
    component: Layout,
    redirect: '/stockManage/stockList',
    name: 'stockManage',
    meta: { role: [superAdmin],title: 'stockManage', icon: 'component'},
    children: [
      {path: 'stockList', name: 'stockList', component:() => import('@/pages/stockManage/stockList'), meta: {title: 'stockList',noCache: true }},
      {path: 'stockAnalysis', name: 'stockAnalysis', component:() => import('@/pages/stockManage/stockAnalysis'), meta: {title: 'stockAnalysis',noCache: true }},
      {path: 'stockAlert', name: 'stockAlert', component:() => import('@/pages/stockManage/stockAlert'), meta: {title: 'stockAlert',noCache: true }},
      {path: 'stockCheck', name: 'stockCheck', component:() => import('@/pages/stockManage/stockCheck'), meta: {title: 'stockCheck',noCache: true }},
    ]
  },
  //分析统计
  {
    path: '/analysisManage',
    component: Layout,
    redirect: '/analysisManage/useReport',
    name: 'analysisManage',
    meta: { role: [superAdmin],title: 'analysisManage', icon: 'component'},
    children: [
      {path: 'useReport', name: 'useReport', component:() => import('@/pages/analysisManage/useReport'), meta: {title: 'useReport',noCache: true }},
      {path: 'consumeCheck', name: 'consumeCheck', component:() => import('@/pages/analysisManage/consumeCheck'), meta: {title: 'consumeCheck',noCache: true }},
      {path: 'consumeReport', name: 'consumeReport', component:() => import('@/pages/analysisManage/consumeReport'), meta: {title: 'consumeReport',noCache: true }},
    ]
  },
  // 地区管理
  {
    path: '/areaManage',
    component: Layout,
    redirect: '/areaManage/userList',
    name: 'areaManage',
    meta: { role: [superAdmin],title: 'areaManage', icon: 'user'},
    children: [
      {path: 'areaList', name: 'areaList', component:() => import('@/pages/areaManage/areaList'), meta: {title: 'areaList',noCache: true }},
      {path: 'companyList', name: 'companyList', component:() => import('@/pages/areaManage/companyList'), meta: {title: 'companyList',noCache: true }},
      {path: 'departmentList', name: 'departmentList', component:() => import('@/pages/areaManage/departmentList'), meta: {title: 'department',noCache: true }},
      {path: 'positionList', name: 'positionList', component:() => import('@/pages/areaManage/positionList'), meta: {title: 'position',noCache: true }},
    ]
  },
  // 用户角色管理
  {
    path: '/userRole',
    component: Layout,
    redirect: '/userRole/userList',
    name: 'userRole',
    meta: { role: [superAdmin],title: 'userRole', icon: 'user'},
    children: [
      {path: 'userList', name: 'userList', component:() => import('@/pages/userRole/userList'), meta: {title: 'userList',noCache: true }},
      {path: 'roleList', name: 'roleList', component:() => import('@/pages/userRole/roleList'), meta: {title: 'roleList',noCache: true }},
      {path: 'flowList', name: 'flowList', component:() => import('@/pages/userRole/flowList'), meta: {title: 'flowList',noCache: true }},
      // {path: 'roleResource', name: 'roleResource', component:() => import('@/pages/userRole/roleResource'), meta: {title: 'roleResource',noCache: true }},
    ]
  },
  /*{
    path: '/test',
    component: Layout,
    redirect: '/test/tableEditQi',
    name: 'test',
    meta: { title: 'test', icon: 'component'},
    children: [
      {path: 'inlineEditTable', name: 'inlineEditTable', component:() => import('@/pages/test/inlineEditTable'), meta: {title: 'inlineEditTable',noCache: true }},

      {path: 'tableEditQi', name: 'tableEditQi', component:() => import('@/pages/test/tableEditQi'), meta: {title: 'tableEditQi',noCache: true }},
      {path: 'index', name: 'index', component:() => import('@/pages/test/index'), meta: {title: 'index',noCache: true }},
      {path: 'backToTop', name: 'backToTop', component:() => import('@/pages/test/backToTop'), meta: {title: 'backToTop',noCache: true }},
      {path: 'index2', name: 'index2', component:() => import('@/pages/test/index2'), meta: {title: 'index2',noCache: true }},
      {path: 'better-scroll', name: 'better-scroll', component:() => import('@/pages/test/better-scroll'), meta: {title: 'better-scroll',noCache: true }},
      {path: 'testscroll', name: 'testscroll', component:() => import('@/pages/test/testscroll'), meta: {title: 'testscroll',noCache: true }},
      // {path: 'subtest', name: 'subtest', component:() => import('@/pages/QueryItem/subtest'), meta: {title: 'subtest',noCache: true }},
    ]
  },*/
 /* //表格测试

//------------------

  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/index',
    alwaysShow: true, // will always show the root menu
    meta: {
      title: 'permission',
      icon: 'lock',
      roles: [superAdmin, editor] // you can set roles in root nav
    },
    children: [
      {
        path: 'page',
        component: () => import('@/views/permission/page'),
        name: 'PagePermission',
        meta: {
          title: 'pagePermission',
          roles: [superAdmin] // or you can only set roles in sub nav
        }
      },
      {
        path: 'directive',
        component: () => import('@/views/permission/directive'),
        name: 'DirectivePermission',
        meta: {
          title: 'directivePermission'
          // if do not set roles, means: this page does not require permission
        }
      }
    ]
  },

  {
    path: '/icon',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/svg-icons/index'),
        name: 'Icons',
        meta: { title: 'icons', icon: 'icon', noCache: true }
      }
    ]
  },

  /!** When your routing table is too long, you can split it into small modules**!/
  adminRouter,
  componentsRouter,

  nestedRouter,
  tableRouter,
  // chartsRouter,


  {
    path: '/example',
    component: Layout,
    redirect: '/example/list',
    name: 'Example',
    meta: {
      title: 'example',
      icon: 'example'
    },
    children: [
      {
        path: 'create',
        component: () => import('@/views/example/create'),
        name: 'CreateArticle',
        meta: { title: 'createArticle', icon: 'edit' }
      },
      {
        path: 'edit/:id(\\d+)',
        component: () => import('@/views/example/edit'),
        name: 'EditArticle',
        meta: { title: 'editArticle', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: () => import('@/views/example/list'),
        name: 'ArticleList',
        meta: { title: 'articleList', icon: 'list' }
      }
    ]
  },

  {
    path: '/tab',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/tab/index'),
        name: 'Tab',
        meta: { title: 'tab', icon: 'tab' }
      }
    ]
  },

  {
    path: '/excel',
    component: Layout,
    redirect: '/excel/export-excel',
    name: 'Excel',
    meta: {
      title: 'excel',
      icon: 'excel'
    },
    children: [
      {
        path: 'export-excel',
        component: () => import('@/views/excel/exportExcel'),
        name: 'ExportExcel',
        meta: { title: 'exportExcel' }
      },
      {
        path: 'export-selected-excel',
        component: () => import('@/views/excel/selectExcel'),
        name: 'SelectExcel',
        meta: { title: 'selectExcel' }
      },
      {
        path: 'upload-excel',
        component: () => import('@/views/excel/uploadExcel'),
        name: 'UploadExcel',
        meta: { title: 'uploadExcel' }
      }
    ]
  },

  {
    path: '/zip',
    component: Layout,
    redirect: '/zip/download',
    alwaysShow: true,
    meta: { title: 'zip', icon: 'zip' },
    children: [
      {
        path: 'download',
        component: () => import('@/views/zip/index'),
        name: 'ExportZip',
        meta: { title: 'exportZip' }
      }
    ]
  },

  {
    path: '/theme',
    component: Layout,
    redirect: 'noredirect',
    children: [
      {
        path: 'index',
        component: () => import('@/views/theme/index'),
        name: 'Theme',
        meta: { title: 'theme', icon: 'theme' }
      }
    ]
  },

  {
    path: '/clipboard',
    component: Layout,
    redirect: 'noredirect',
    children: [
      {
        path: 'index',
        component: () => import('@/views/clipboard/index'),
        name: 'ClipboardDemo',
        meta: { title: 'clipboardDemo', icon: 'clipboard' }
      }
    ]
  },

  {
    path: '/i18n',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/i18n-demo/index'),
        name: 'I18n',
        meta: { title: 'i18n', icon: 'international' }
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://github.com/PanJiaChen/vue-element-admin',
        meta: { title: 'externalLink', icon: 'link' }
      }
    ]
  },


  {
    path: '/error',
    component: Layout,
    redirect: 'noredirect',
    name: 'ErrorPages',
    meta: {
      title: 'errorPages',
      icon: '404'
    },
    children: [
      {
        path: '401',
        component: () => import('@/views/errorPage/401'),
        name: 'Page401',
        meta: { title: 'page401', noCache: true }
      },
      {
        path: '404',
        component: () => import('@/views/errorPage/404'),
        name: 'Page404',
        meta: { title: 'page404', noCache: true }
      }
    ]
  },

  {
    path: '/error-log',
    component: Layout,
    redirect: 'noredirect',
    children: [
      {
        path: 'log',
        component: () => import('@/views/errorLog/index'),
        name: 'ErrorLog',
        meta: { title: 'errorLog', icon: 'bug' }
      }
    ]
  },
 */
  { path: '*', redirect: '/404', hidden: true }
]

